# Copyright 2020 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_python//python:proto.bzl", "py_proto_library")

# Load proto_library
load("//xls/build_rules:xls_build_defs.bzl", "xls_ir_verilog")
# cc_proto_library is used in this file

package(
    default_applicable_licenses = ["//:license"],
    default_visibility = ["//xls:xls_internal"],
    features = [
        "layering_check",
        "parse_headers",
    ],
    licenses = ["notice"],  # Apache 2.0
)

cc_library(
    name = "name_to_bit_count",
    hdrs = ["name_to_bit_count.h"],
    deps = [
        "//xls/ir:bits",
        "@com_google_absl//absl/container:flat_hash_map",
    ],
)

cc_library(
    name = "fifo_model_test_utils",
    testonly = True,
    hdrs = ["fifo_model_test_utils.h"],
    deps = [
        "//xls/common/fuzzing:fuzztest",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:value",
        "@com_google_absl//absl/container:flat_hash_map",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "combinational_generator",
    srcs = ["combinational_generator.cc"],
    hdrs = ["combinational_generator.h"],
    deps = [
        ":block_conversion",
        ":block_generator",
        ":block_metrics",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_pass_pipeline",
        ":codegen_residual_data_cc_proto",
        ":codegen_result",
        ":module_signature",
        ":verilog_line_map_cc_proto",
        ":xls_metrics_cc_proto",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/ir",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "combinational_generator_test",
    srcs = ["combinational_generator_test.cc"],
    data = glob([
        "testdata/combinational_generator_test_*",
    ]),
    shard_count = 50,
    deps = [
        ":combinational_generator",
        "//xls/codegen/vast",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/examples:sample_packages",
        "//xls/interpreter:ir_interpreter",
        "//xls/interpreter:random_value",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:events",
        "//xls/ir:function_builder",
        "//xls/ir:ir_parser",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "//xls/simulation:module_simulator",
        "//xls/simulation:module_testbench",
        "//xls/simulation:module_testbench_thread",
        "//xls/simulation:verilog_test_base",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "trace_test",
    srcs = ["trace_test.cc"],
    data = glob([
        "testdata/trace_test_*",
    ]),
    deps = [
        ":codegen_options",
        ":codegen_result",
        ":combinational_generator",
        ":pipeline_generator",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_parser",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "//xls/simulation:module_testbench",
        "//xls/simulation:module_testbench_thread",
        "//xls/simulation:verilog_test_base",
        "@com_google_absl//absl/status",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "finite_state_machine",
    srcs = ["finite_state_machine.cc"],
    hdrs = ["finite_state_machine.h"],
    deps = [
        "//xls/codegen/vast",
        "//xls/common:casts",
        "//xls/common/status:status_macros",
        "//xls/ir:bits",
        "//xls/ir:source_location",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "finite_state_machine_test",
    srcs = ["finite_state_machine_test.cc"],
    data = glob(["testdata/finite_state_machine_test_*"]),
    deps = [
        ":finite_state_machine",
        "//xls/codegen/vast",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir:source_location",
        "//xls/simulation:verilog_test_base",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "pipeline_generator",
    srcs = ["pipeline_generator.cc"],
    hdrs = ["pipeline_generator.h"],
    deps = [
        ":block_conversion",
        ":block_generator",
        ":block_metrics",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_pass_pipeline",
        ":codegen_residual_data_cc_proto",
        ":codegen_result",
        ":module_signature",
        ":verilog_line_map_cc_proto",
        ":xls_metrics_cc_proto",
        "//xls/common/logging:log_lines",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/ir",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "convert_ir_to_blocks_passes",
    srcs = ["convert_ir_to_blocks_passes.cc"],
    hdrs = ["convert_ir_to_blocks_passes.h"],
    deps = [
        ":bdd_io_analysis",
        ":block_conversion",
        ":codegen_pass",
        ":codegen_util",
        ":conversion_utils",
        "//xls/common/logging:log_lines",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "//xls/ir:state_element",
        "//xls/ir:xls_ir_interface_cc_proto",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "block_conversion_dead_token_removal_pass",
    srcs = ["block_conversion_dead_token_removal_pass.cc"],
    hdrs = ["block_conversion_dead_token_removal_pass.h"],
    deps = [
        ":codegen_checker",
        ":codegen_pass",
        ":codegen_wrapper_pass",
        ":register_legalization_pass",
        "//xls/passes:dataflow_simplification_pass",
        "//xls/passes:dce_pass",
        "//xls/passes:optimization_pass",
    ],
)

cc_library(
    name = "block_conversion_pass_pipeline",
    srcs = ["block_conversion_pass_pipeline.cc"],
    hdrs = ["block_conversion_pass_pipeline.h"],
    deps = [
        ":block_conversion_dead_token_removal_pass",
        ":codegen_options",
        ":codegen_pass",
        ":convert_ir_to_blocks_passes",
        ":mark_channel_fifos_pass",
        "//xls/codegen/passes_ng:block_pipeline_inserter_pass",
        "//xls/codegen/passes_ng:flow_control_simplification_pass",
        "//xls/codegen/passes_ng:metadata_conversion_pass",
        "//xls/codegen/passes_ng:stage_to_block_conversion_pass",
        "//xls/codegen/vast",
        "//xls/common/status:ret_check",
        "//xls/ir",
        "//xls/ir:name_uniquer",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "unified_generator",
    srcs = ["unified_generator.cc"],
    hdrs = ["unified_generator.h"],
    deps = [
        ":block_conversion_pass_pipeline",
        ":block_generator",
        ":block_metrics",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_pass_pipeline",
        ":codegen_residual_data_cc_proto",
        ":codegen_result",
        ":module_signature",
        ":verilog_line_map_cc_proto",
        ":xls_metrics_cc_proto",
        "//xls/codegen/passes_ng:stage_conversion_pass_pipeline",
        "//xls/common/logging:log_lines",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/ir",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "module_signature",
    srcs = ["module_signature.cc"],
    hdrs = ["module_signature.h"],
    deps = [
        ":module_signature_cc_proto",
        "//xls/common:proto_adaptor_utils",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_cc_proto",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:xls_type_cc_proto",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "node_expressions",
    srcs = ["node_expressions.cc"],
    hdrs = ["node_expressions.h"],
    deps = [
        ":codegen_options",
        ":expression_flattening",
        "//xls/codegen/vast",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value_flattening",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "expression_flattening",
    srcs = ["expression_flattening.cc"],
    hdrs = ["expression_flattening.h"],
    deps = [
        "//xls/codegen/vast",
        "//xls/common/status:ret_check",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value_flattening",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "lint_annotate",
    srcs = ["lint_annotate.cc"],
    hdrs = ["lint_annotate.h"],
    deps = [
        "//xls/codegen/vast",
        "//xls/ir:source_location",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "module_builder",
    srcs = ["module_builder.cc"],
    hdrs = ["module_builder.h"],
    deps = [
        ":codegen_options",
        ":expression_flattening",
        ":lint_annotate",
        ":module_signature_cc_proto",
        ":node_expressions",
        ":node_representation",
        "//xls/codegen/vast",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:format_preference",
        "//xls/ir:format_strings",
        "//xls/ir:name_uniquer",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_flattening",
        "//xls/passes:bdd_query_engine",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "conversion_utils",
    srcs = ["conversion_utils.cc"],
    hdrs = ["conversion_utils.h"],
    deps = [
        ":codegen_options",
        ":codegen_pass",
        ":register_legalization_pass",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "//xls/ir:xls_ir_interface_cc_proto",
        "//xls/passes:dataflow_simplification_pass",
        "//xls/passes:dce_pass",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@re2",
    ],
)

cc_library(
    name = "clone_nodes_into_block_handler",
    srcs = ["clone_nodes_into_block_handler.cc"],
    hdrs = ["clone_nodes_into_block_handler.h"],
    deps = [
        ":codegen_options",
        ":codegen_pass",
        ":concurrent_stage_groups",
        ":conversion_utils",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:state_element",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "//xls/ir:xls_ir_interface_cc_proto",
        "//xls/scheduling:pipeline_schedule",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "block_conversion",
    srcs = [
        "block_conversion.cc",
        "proc_block_conversion.cc",
    ],
    hdrs = [
        "block_conversion.h",
        "proc_block_conversion.h",
    ],
    deps = [
        ":bdd_io_analysis",
        ":clone_nodes_into_block_handler",
        ":codegen_options",
        ":codegen_pass",
        ":concurrent_stage_groups",
        ":conversion_utils",
        ":mark_channel_fifos_pass",
        ":ram_configuration",
        "//xls/common:casts",
        "//xls/common/logging:log_lines",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:name_uniquer",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:state_element",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:xls_ir_interface_cc_proto",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:nullability",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "codegen_pass",
    srcs = ["codegen_pass.cc"],
    hdrs = ["codegen_pass.h"],
    deps = [
        ":codegen_options",
        ":concurrent_stage_groups",
        "//xls/codegen/passes_ng:stage_conversion",
        "//xls/codegen/passes_ng:stage_to_block_conversion_metadata",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "@com_google_absl//absl/base:nullability",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
    ],
)

cc_library(
    name = "codegen_options",
    srcs = ["codegen_options.cc"],
    hdrs = ["codegen_options.h"],
    deps = [
        ":codegen_residual_data_cc_proto",
        ":module_signature_cc_proto",
        ":op_override",
        ":ram_configuration",
        "//xls/common:proto_adaptor_utils",
        "//xls/ir:channel",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:xls_ir_interface_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "signature_generation_pass",
    srcs = ["signature_generation_pass.cc"],
    hdrs = ["signature_generation_pass.h"],
    deps = [
        ":codegen_pass",
        ":module_signature",
        ":signature_generator",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "codegen_pass_pipeline",
    srcs = ["codegen_pass_pipeline.cc"],
    hdrs = ["codegen_pass_pipeline.h"],
    deps = [
        ":block_stitching_pass",
        ":codegen_checker",
        ":codegen_pass",
        ":codegen_wrapper_pass",
        ":ffi_instantiation_pass",
        ":maybe_materialize_fifos_pass",
        ":mulp_combining_pass",
        ":name_legalization_pass",
        ":port_legalization_pass",
        ":priority_select_reduction_pass",
        ":ram_rewrite_pass",
        ":register_combining_pass",
        ":register_legalization_pass",
        ":side_effect_condition_pass",
        ":signature_generation_pass",
        ":trace_verbosity_pass",
        "//xls/ir",
        "//xls/passes:basic_simplification_pass",
        "//xls/passes:cse_pass",
        "//xls/passes:dce_pass",
        "//xls/passes:identity_removal_pass",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "port_legalization_pass",
    srcs = ["port_legalization_pass.cc"],
    hdrs = ["port_legalization_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:value_utils",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "priority_select_reduction_pass",
    srcs = ["priority_select_reduction_pass.cc"],
    hdrs = ["priority_select_reduction_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/codegen/vast",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:value",
        "//xls/passes:bdd_query_engine",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "name_legalization_pass",
    srcs = ["name_legalization_pass.cc"],
    hdrs = ["name_legalization_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/codegen/vast:verilog_keywords",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:register",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "signature_generator",
    srcs = ["signature_generator.cc"],
    hdrs = ["signature_generator.h"],
    deps = [
        ":codegen_options",
        ":codegen_pass",
        ":module_signature",
        ":module_signature_cc_proto",
        "//xls/codegen/vast",
        "//xls/common:casts",
        "//xls/common/logging:log_lines",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:channel_cc_proto",
        "//xls/ir:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "codegen_checker",
    srcs = ["codegen_checker.cc"],
    hdrs = ["codegen_checker.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:register",
        "//xls/ir:verifier",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "block_generator",
    srcs = ["block_generator.cc"],
    hdrs = ["block_generator.h"],
    deps = [
        ":codegen_options",
        ":codegen_residual_data_cc_proto",
        ":conversion_utils",
        ":expression_flattening",
        ":module_builder",
        ":module_signature_cc_proto",
        ":node_expressions",
        ":node_representation",
        ":op_override",
        ":op_override_impls",
        ":verilog_line_map_cc_proto",
        "//xls/codegen/vast",
        "//xls/common/logging:log_lines",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:format_preference",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/random:bit_gen_ref",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "register_chaining_analysis",
    srcs = ["register_chaining_analysis.cc"],
    hdrs = ["register_chaining_analysis.h"],
    deps = [
        ":codegen_pass",
        ":concurrent_stage_groups",
        "//xls/ir",
        "//xls/ir:register",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "block_execution_fuzz_test",
    srcs = ["block_execution_fuzz_test.cc"],
    data = [
        "//xls/examples:custom_schedule.block.ir",
        "//xls/examples:custom_schedule.codegen_options.textproto",
        "//xls/examples:custom_schedule.opt.ir",
        "//xls/examples:custom_schedule.schedule_options.textproto",
        "//xls/examples:custom_schedule.sig.textproto",
    ],
    deps = [
        ":module_signature_cc_proto",
        "//xls/common:xls_gunit_main",
        "//xls/common/file:filesystem",
        "//xls/common/file:get_runfile_path",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/data_structures:inline_bitmap",
        "//xls/interpreter:block_evaluator",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:register",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "//xls/ir:xls_type_cc_proto",
        "//xls/jit:block_jit",
        "//xls/public:ir_parser",
        "//xls/scheduling:scheduling_options",
        "//xls/tools:codegen",
        "//xls/tools:codegen_flags_cc_proto",
        "//xls/tools:scheduling_options_flags_cc_proto",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_protobuf//:protobuf",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "register_chaining_analysis_test",
    srcs = ["register_chaining_analysis_test.cc"],
    deps = [
        ":codegen_pass",
        ":concurrent_stage_groups",
        ":register_chaining_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "concurrent_stage_groups",
    srcs = ["concurrent_stage_groups.cc"],
    hdrs = ["concurrent_stage_groups.h"],
    deps = [
        "//xls/data_structures:inline_bitmap",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "register_combining_pass",
    srcs = ["register_combining_pass.cc"],
    hdrs = ["register_combining_pass.h"],
    deps = [
        ":codegen_options",
        ":codegen_pass",
        ":register_chaining_analysis",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:register",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "register_legalization_pass",
    srcs = ["register_legalization_pass.cc"],
    hdrs = ["register_legalization_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:register",
        "//xls/ir:value_utils",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "codegen_wrapper_pass",
    srcs = ["codegen_wrapper_pass.cc"],
    hdrs = ["codegen_wrapper_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

proto_library(
    name = "module_signature_proto",
    srcs = ["module_signature.proto"],
    deps = [
        ":xls_metrics_proto",
        "//xls/ir:channel_proto",
        "//xls/ir:foreign_function_data_proto",
        "//xls/ir:xls_type_proto",
        "@googleapis//google/api:field_behavior_proto",
    ],
)

cc_proto_library(
    name = "module_signature_cc_proto",
    deps = [":module_signature_proto"],
)

py_proto_library(
    name = "module_signature_py_pb2",
    deps = [":module_signature_proto"],
)

proto_library(
    name = "xls_metrics_proto",
    srcs = ["xls_metrics.proto"],
    deps = ["//xls/ir:op_proto"],
)

cc_proto_library(
    name = "xls_metrics_cc_proto",
    deps = [
        ":xls_metrics_proto",
    ],
)

py_proto_library(
    name = "xls_metrics_py_pb2",
    deps = [":xls_metrics_proto"],
)

proto_library(
    name = "verilog_line_map_proto",
    srcs = ["verilog_line_map.proto"],
)

cc_proto_library(
    name = "verilog_line_map_cc_proto",
    deps = [":verilog_line_map_proto"],
)

py_proto_library(
    name = "verilog_line_map_py_pb2",
    deps = [":verilog_line_map_proto"],
)

proto_library(
    name = "codegen_residual_data_proto",
    srcs = ["codegen_residual_data.proto"],
)

cc_proto_library(
    name = "codegen_residual_data_cc_proto",
    deps = [":codegen_residual_data_proto"],
)

py_proto_library(
    name = "codegen_residual_data_py_pb2",
    deps = [":codegen_residual_data_proto"],
)

cc_test(
    name = "pipeline_generator_test",
    srcs = ["pipeline_generator_test.cc"],
    data = glob([
        "testdata/pipeline_generator_test_*",
    ]),
    shard_count = 50,
    deps = [
        ":codegen_options",
        ":codegen_result",
        ":module_signature",
        ":module_signature_cc_proto",
        ":pipeline_generator",
        ":test_fifos",
        "//xls/common:golden_files",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:ir_parser",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "//xls/ir:value",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "//xls/simulation:module_simulator",
        "//xls/simulation:module_testbench",
        "//xls/simulation:module_testbench_thread",
        "//xls/simulation:verilog_include",
        "//xls/simulation:verilog_test_base",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "module_signature_test",
    srcs = ["module_signature_test.cc"],
    deps = [
        ":module_signature",
        ":module_signature_cc_proto",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_cc_proto",
        "//xls/ir:ir_matcher",
        "//xls/ir:value",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "expression_flattening_test",
    srcs = ["expression_flattening_test.cc"],
    deps = [
        ":expression_flattening",
        "//xls/codegen/vast",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "module_builder_test",
    srcs = ["module_builder_test.cc"],
    data = glob(["testdata/module_builder_test_*"]),
    shard_count = 10,
    deps = [
        ":module_builder",
        ":module_signature_cc_proto",
        "//xls/codegen/vast",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/simulation:verilog_test_base",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "block_conversion_test_fixture",
    testonly = True,
    hdrs = ["block_conversion_test_fixture.h"],
    deps = [
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir:ir_test_base",
        "//xls/tools:codegen",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/random:bit_gen_ref",
        "@com_google_absl//absl/random:distributions",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "block_conversion_test",
    srcs = ["block_conversion_test.cc"],
    shard_count = 50,
    deps = [
        ":block_conversion",
        ":block_conversion_test_fixture",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_result",
        ":ram_configuration",
        "//xls/common:casts",
        "//xls/common:xls_gunit_main",
        "//xls/common/logging:log_lines",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/interpreter:block_evaluator",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:clone_package",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "//xls/ir:verifier",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "//xls/scheduling:scheduling_result",
        "//xls/tools:codegen",
        "//xls/tools:codegen_flags_cc_proto",
        "//xls/tools:scheduling_options_flags_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/random:bit_gen_ref",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "signature_generator_test",
    srcs = ["signature_generator_test.cc"],
    deps = [
        ":block_conversion",
        ":codegen_options",
        ":codegen_pass",
        ":module_signature",
        ":module_signature_cc_proto",
        ":signature_generator",
        "//xls/common:xls_gunit_main",
        "//xls/common/logging:log_lines",
        "//xls/common/status:matchers",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:channel_cc_proto",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_parser",
        "//xls/ir:type",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "block_inlining_pass_test",
    srcs = ["block_inlining_pass_test.cc"],
    deps = [
        ":block_inlining_pass",
        ":codegen_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/interpreter:block_evaluator",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:foreign_function_data_cc_proto",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "port_legalization_pass_test",
    srcs = ["port_legalization_pass_test.cc"],
    deps = [
        ":block_conversion",
        ":codegen_options",
        ":codegen_pass",
        ":port_legalization_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "name_legalization_pass_test",
    srcs = ["name_legalization_pass_test.cc"],
    data = glob([
        "testdata/name_legalization_pass_test_*",
    ]),
    deps = [
        ":block_generator",
        ":codegen_options",
        ":codegen_pass",
        ":combinational_generator",
        ":name_legalization_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/passes:pass_base",
        "//xls/simulation:verilog_test_base",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "block_generator_test",
    srcs = ["block_generator_test.cc"],
    data = glob([
        "testdata/block_generator_test_*",
    ]),
    shard_count = 10,
    deps = [
        ":block_conversion",
        ":block_generator",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_pass_pipeline",
        ":codegen_result",
        ":module_signature",
        ":op_override",
        ":signature_generator",
        ":test_fifos",
        "//xls/common:xls_gunit_main",
        "//xls/common/logging:log_lines",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:bit_push_buffer",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "//xls/scheduling:scheduling_result",
        "//xls/simulation:module_simulator",
        "//xls/simulation:module_testbench",
        "//xls/simulation:module_testbench_thread",
        "//xls/simulation:testbench_signal_capture",
        "//xls/simulation:verilog_include",
        "//xls/simulation:verilog_test_base",
        "//xls/tools:codegen",
        "//xls/tools:codegen_flags_cc_proto",
        "//xls/tools:scheduling_options_flags_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "register_combining_pass_test",
    srcs = ["register_combining_pass_test.cc"],
    deps = [
        ":block_conversion",
        ":codegen_options",
        ":codegen_pass",
        ":register_combining_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:state_element",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "register_legalization_pass_test",
    srcs = ["register_legalization_pass_test.cc"],
    deps = [
        ":codegen_pass",
        ":register_legalization_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "codegen_wrapper_pass_test",
    srcs = ["codegen_wrapper_pass_test.cc"],
    deps = [
        ":codegen_pass",
        ":codegen_wrapper_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/passes:dce_pass",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "block_metrics",
    srcs = ["block_metrics.cc"],
    hdrs = ["block_metrics.h"],
    deps = [
        ":xls_metrics_cc_proto",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "block_metrics_test",
    srcs = ["block_metrics_test.cc"],
    deps = [
        ":block_conversion",
        ":block_metrics",
        ":codegen_options",
        ":codegen_pass",
        ":xls_metrics_cc_proto",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:op",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "bdd_io_analysis",
    srcs = ["bdd_io_analysis.cc"],
    hdrs = ["bdd_io_analysis.h"],
    deps = [
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:node_util",
        "//xls/passes:bdd_query_engine",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "bdd_io_analysis_test",
    srcs = ["bdd_io_analysis_test.cc"],
    deps = [
        ":bdd_io_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "op_override",
    srcs = [],
    hdrs = ["op_override.h"],
    deps = ["@com_google_absl//absl/container:flat_hash_map"],
)

cc_library(
    name = "op_override_impls",
    srcs = ["op_override_impls.cc"],
    hdrs = ["op_override_impls.h"],
    deps = [
        ":module_builder",
        ":node_representation",
        ":op_override",
        "//xls/codegen/vast",
        "//xls/common:visitor",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:op",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
        "@re2",
    ],
)

cc_library(
    name = "node_representation",
    srcs = [],
    hdrs = ["node_representation.h"],
    deps = [
        "//xls/codegen/vast",
    ],
)

cc_library(
    name = "mulp_combining_pass",
    srcs = ["mulp_combining_pass.cc"],
    hdrs = ["mulp_combining_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "mulp_combining_pass_test",
    srcs = ["mulp_combining_pass_test.cc"],
    deps = [
        ":codegen_pass",
        ":mulp_combining_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "ffi_instantiation_pass",
    srcs = ["ffi_instantiation_pass.cc"],
    hdrs = ["ffi_instantiation_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/codegen/vast",
        "//xls/common:casts",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:code_template",
        "//xls/ir:type",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "ffi_instantiation_pass_test",
    srcs = ["ffi_instantiation_pass_test.cc"],
    deps = [
        ":codegen_pass",
        ":ffi_instantiation_pass",
        "//xls/common:casts",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:foreign_function",
        "//xls/ir:foreign_function_data_cc_proto",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:type",
        "//xls/ir:verifier",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "ram_configuration",
    srcs = ["ram_configuration.cc"],
    hdrs = ["ram_configuration.h"],
    deps = [
        "//xls/scheduling:scheduling_options",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_library(
    name = "ram_rewrite_pass",
    srcs = ["ram_rewrite_pass.cc"],
    hdrs = ["ram_rewrite_pass.h"],
    deps = [
        ":block_conversion",
        ":codegen_pass",
        ":module_signature",
        ":module_signature_cc_proto",
        ":ram_configuration",
        "//xls/common:visitor",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_test(
    name = "ram_rewrite_pass_test",
    srcs = ["ram_rewrite_pass_test.cc"],
    deps = [
        ":block_conversion",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_pass_pipeline",
        ":module_signature",
        ":module_signature_cc_proto",
        ":ram_configuration",
        ":ram_rewrite_pass",
        "//xls/common:proto_test_utils",
        "//xls/common:visitor",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:verifier",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "side_effect_condition_pass",
    srcs = ["side_effect_condition_pass.cc"],
    hdrs = ["side_effect_condition_pass.h"],
    deps = [
        ":codegen_pass",
        ":conversion_utils",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "side_effect_condition_pass_test",
    srcs = ["side_effect_condition_pass_test.cc"],
    deps = [
        ":block_conversion",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_pass_pipeline",
        ":side_effect_condition_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/interpreter:block_evaluator",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:events",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "//xls/scheduling:scheduling_pass",
        "//xls/scheduling:scheduling_pass_pipeline",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "block_stitching_pass",
    srcs = ["block_stitching_pass.cc"],
    hdrs = ["block_stitching_pass.h"],
    deps = [
        ":codegen_options",
        ":codegen_pass",
        ":conversion_utils",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:name_uniquer",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "maybe_materialize_fifos_pass",
    srcs = ["maybe_materialize_fifos_pass.cc"],
    hdrs = ["maybe_materialize_fifos_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:block_elaboration",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:name_uniquer",
        "//xls/ir:register",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value_utils",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "maybe_materialize_fifos_pass_test",
    srcs = ["maybe_materialize_fifos_pass_test.cc"],
    deps = [
        ":codegen_pass",
        ":fifo_model_test_utils",
        ":maybe_materialize_fifos_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/interpreter:block_evaluator",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:name_uniquer",
        "//xls/ir:type",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "block_inlining_pass",
    srcs = ["block_inlining_pass.cc"],
    hdrs = ["block_inlining_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:block_elaboration",
        "//xls/ir:register",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "trace_verbosity_pass",
    srcs = ["trace_verbosity_pass.cc"],
    hdrs = ["trace_verbosity_pass.h"],
    deps = [
        ":codegen_pass",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "trace_verbosity_pass_test",
    srcs = ["trace_verbosity_pass_test.cc"],
    deps = [
        ":codegen_pass",
        ":trace_verbosity_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "block_stitching_pass_test",
    srcs = ["block_stitching_pass_test.cc"],
    shard_count = 10,
    # RandomProcNetworks test can time out with sanitizers.
    tags = ["optonly"],
    deps = [
        ":block_conversion",
        ":block_stitching_pass",
        ":codegen_options",
        ":codegen_pass",
        ":module_signature_cc_proto",
        ":side_effect_condition_pass",
        ":signature_generation_pass",
        "//xls/common:source_location",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/interpreter:block_evaluator",
        "//xls/interpreter:channel_queue",
        "//xls/interpreter:interpreter_proc_runtime",
        "//xls/interpreter:ir_interpreter",
        "//xls/interpreter:serial_proc_runtime",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:events",
        "//xls/ir:foreign_function",
        "//xls/ir:foreign_function_data_cc_proto",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "//xls/passes:channel_legalization_pass",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "//xls/scheduling:scheduling_result",
        "//xls/tools:codegen",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/random:distributions",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "mark_channel_fifos_pass",
    srcs = ["mark_channel_fifos_pass.cc"],
    hdrs = ["mark_channel_fifos_pass.h"],
    deps = [
        ":codegen_options",
        ":codegen_pass",
        "//xls/common:casts",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "mark_channel_fifos_pass_test",
    srcs = ["mark_channel_fifos_pass_test.cc"],
    deps = [
        ":codegen_options",
        ":codegen_pass",
        ":mark_channel_fifos_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/passes:pass_base",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "synchronous_procs_test",
    srcs = ["synchronous_procs_test.cc"],
    data = glob([
        "testdata/synchronous_procs_test_*",
    ]),
    deps = [
        ":codegen_options",
        ":codegen_result",
        ":module_signature_cc_proto",
        ":pipeline_generator",
        ":test_fifos",
        "//xls/common:casts",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "//xls/scheduling:pipeline_schedule",
        "//xls/scheduling:run_pipeline_schedule",
        "//xls/scheduling:scheduling_options",
        "//xls/simulation:module_simulator",
        "//xls/simulation:verilog_include",
        "//xls/simulation:verilog_test_base",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "test_fifos",
    testonly = True,
    hdrs = ["test_fifos.h"],
    deps = ["//xls/ir:channel"],
)

cc_library(
    name = "codegen_util",
    srcs = ["codegen_util.cc"],
    hdrs = ["codegen_util.h"],
    deps = [
        "//xls/common/status:status_macros",
        "//xls/ir",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "codegen_result",
    hdrs = ["codegen_result.h"],
    visibility = ["//xls:xls_users"],
    deps = [
        ":codegen_residual_data_cc_proto",
        ":module_signature",
        ":verilog_line_map_cc_proto",
        ":xls_metrics_cc_proto",
        "//xls/passes:pass_metrics_cc_proto",
    ],
)

# Test that codegen args work correctly in our rules.
xls_ir_verilog(
    name = "assertions_multiple_ifdef_guards",
    src = "//xls/examples/assertions:assertions_opt_ir",
    codegen_args = {
        "module_name": "assertions_top",
        "generator": "combinational",
        "delay_model": "unit",
        "use_system_verilog": "true",
        "assertion_macro_names": "ASSERT_ON,!SYNTHESIS",
    },
    verilog_file = "assertions_comb_multiple_ifdef_guards.sv",
)

xls_ir_verilog(
    name = "assertions_no_ifdef_guards",
    src = "//xls/examples/assertions:assertions_opt_ir",
    codegen_args = {
        "module_name": "assertions_top",
        "generator": "combinational",
        "delay_model": "unit",
        "use_system_verilog": "true",
        "assertion_macro_names": "",
    },
    verilog_file = "assertions_comb_no_ifdef_guards.sv",
)

diff_test(
    name = "assertions_multiple_ifdef_guards_diff_test",
    file1 = ":assertions_comb_multiple_ifdef_guards.sv",
    file2 = "testdata/assertions_comb_multiple_ifdef_guards.svtxt",
)

diff_test(
    name = "assertions_no_ifdef_guards_diff_test",
    file1 = ":assertions_comb_no_ifdef_guards.sv",
    file2 = "testdata/assertions_comb_no_ifdef_guards.svtxt",
)

cc_test(
    name = "priority_select_reduction_pass_test",
    srcs = ["priority_select_reduction_pass_test.cc"],
    deps = [
        ":block_conversion",
        ":codegen_options",
        ":codegen_pass",
        ":codegen_pass_pipeline",
        ":codegen_wrapper_pass",
        ":priority_select_reduction_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "//xls/passes:dce_pass",
        "//xls/passes:optimization_pass",
        "//xls/passes:pass_base",
        "//xls/scheduling:pipeline_schedule",
        "//xls/solvers:z3_assert_testutils",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:status_matchers",
        "@googletest//:gtest",
    ],
)
